<template>
  <div class="wrapper">
    <avatar :src="props.avatar" class="avatar"></avatar>
    <!-- <el-avatar :size="50" :src="circleUrl" /> -->
    <textarea
      ref="textareaRef"
      v-model="inputValue"
      cols="80"
      name="msg"
      rows="5"
      :placeholder="props.placeholder"
      class="input"
    ></textarea>
    <button class="btn" @click="handleClick">发表评论</button>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, watch } from "vue";
import Avatar from "@/components/Avatar.vue";

const props = defineProps({
  avatar: {
    type: String,
  },
  modelValue: {
    type: String,
    default: "",
  },
  placeholder: {
    type: String,
    default: "说一说您的观点吧",
  },
});

const emit = defineEmits(["submit", "update:modelValue"]);

const inputValue = ref(props.modelValue);

watch(
  () => inputValue.value,
  (val) => {
    emit("update:modelValue", val);
  }
);

const handleClick = () => {
  if (inputValue.value.trim() == "") {
    return;
  }
  emit("submit", inputValue.value);
};

const textareaRef = ref<HTMLElement>();

function focus() {
  textareaRef.value?.focus();
}

function clear() {
  inputValue.value = "";
}

defineExpose({
  clear,
  focus,
});
</script>

<style scoped lang="less">
.wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.avatar {
  /* width: 40px;
  height: 40px;
  border-radius: 50%; */
  /* padding: 0 10px; */
}

.input {
  font-size: 12px;
  display: inline-block;
  box-sizing: border-box;
  background-color: #f4f5f7;
  border: 1px solid #e5e9ef;
  overflow: auto;
  border-radius: 4px;
  color: #555;
  width: 100%;
  height: 65px;
  transition: 0s;
  padding: 5px 10px;
  line-height: normal;
  outline: none;
  margin: 0 0.625rem;

  font-family: inherit;
  resize: none;
  transition: var(--transition-duration);

  &:focus {
    background-color: #fff;
    border: 1px solid var(--app-main-color);
  }
}

.btn {
  width: 70px;
  height: 64px;
  /* position: absolute;
  right: -80px;
  top: 0; */
  padding: 4px 15px;
  /* margin-left: 0.5rem; */
  font-size: 14px;
  color: #fff;
  border-radius: 4px;
  text-align: center;
  min-width: 60px;
  vertical-align: top;
  cursor: pointer;
  background-color: #00a1d6;
  border: 1px solid #00a1d6;
  transition: 0.1s;
  user-select: none;
  outline: none;
}
</style>
